package com.example.springDemo.controller;

import com.example.springDemo.bean.UserLong;
import com.example.springDemo.service.UserLongService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController//==@Controller+@ResponseBody
//@Controller//开启控制器（必须）
public class sqlQuery {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Autowired
    UserLongService userLongService;

    @GetMapping("/sql")
    public String query(){
        Long aLong = jdbcTemplate.queryForObject("select count(*) from user_long", Long.class);
        return aLong.toString();
    }

    @GetMapping("/userid")
    public UserLong getById(){
        System.out.println("1111");
        return userLongService.getUserById(1L);
    }

    @PostMapping("/userinin")
    public UserLong saveUserLong(UserLong userLong){

        userLongService.setUserLong(userLong);
        return  userLong;
    }

}
